
from feature import Feature, FeatureParser, registerFeatureParserClass

class CodonFeature(Feature):

    def getDetails(self):
        cols = self.content.strip().split("\t")
        (ucscId, chr, strand, pos, codonNum, codon, readingFrame) = tuple(cols)
        self.ucscId = ucscId
        self.strand = strand
        self.codonNum = codonNum
        self.codon = codon
        self.readingFrame = readingFrame
        return self

class CodonFeatureParser(FeatureParser):
    '''
    Parser for lines in ucsc-codon-info.txt files.
    Parses tab-separated string:
    uc009vjh.1	chr1	+	58957	1	GTG	1
    '''
    def parse(self, line):
        if line == None or line.startswith("#"): return None
        cols = line.strip().split("\t")
        if len(cols)<7: return None
        return CodonFeature(cols[1], cols[3], cols[3], line)
    def getMaxFeatureSize(self):
        return 1

registerFeatureParserClass("ucsc-codon-info", CodonFeatureParser)
registerFeatureParserClass("ccds-codon-info", CodonFeatureParser)
